<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/72X72.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/48X48.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/32X32.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"issacyoung.cn","root":"/","scheme":"Pisces","version":"7.7.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="Chapter 1 Reliable Scalable and常见的数据系统 存储数据，以便之后再次使用 - 数据库 记住一些非常 重的操作结构，方便之后加速读取速度 - 缓存 允许用户以各种关键字搜索，以各种条件过滤数据 - 搜索引擎 源源不断的产生数据，并发发给其他进程进行处理 - 流式处理 定期处理累积的大量数据 - 批处理 进行消息的转发和分发 - 消息队列  ddia 提供了一种典型的数">
<meta property="og:type" content="article">
<meta property="og:title" content="一步一步之ddia">
<meta property="og:url" content="http://issacyoung.cn/2023/11/25/%E4%B8%80%E6%AD%A5%E4%B8%80%E6%AD%A5%E4%B9%8Bddia/index.html">
<meta property="og:site_name" content="Young‘s River">
<meta property="og:description" content="Chapter 1 Reliable Scalable and常见的数据系统 存储数据，以便之后再次使用 - 数据库 记住一些非常 重的操作结构，方便之后加速读取速度 - 缓存 允许用户以各种关键字搜索，以各种条件过滤数据 - 搜索引擎 源源不断的产生数据，并发发给其他进程进行处理 - 流式处理 定期处理累积的大量数据 - 批处理 进行消息的转发和分发 - 消息队列  ddia 提供了一种典型的数">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-11-25T15:06:03.000Z">
<meta property="article:modified_time" content="2023-12-28T14:24:14.962Z">
<meta property="article:author" content="Issac Young">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://issacyoung.cn/2023/11/25/%E4%B8%80%E6%AD%A5%E4%B8%80%E6%AD%A5%E4%B9%8Bddia/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>一步一步之ddia | Young‘s River</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Young‘s River" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Young‘s River</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">一个正能量的程序员，喜欢码字，热爱运动，向往自由</p>
  </div>

  <div class="site-nav-right"></div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/IssacYoung2013" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://issacyoung.cn/2023/11/25/%E4%B8%80%E6%AD%A5%E4%B8%80%E6%AD%A5%E4%B9%8Bddia/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/author.jpg">
      <meta itemprop="name" content="Issac Young">
      <meta itemprop="description" content="现代生活工作节奏越来越快，需要有时间和空间沉淀积累，将知识点规划成树，记录自己的感悟心得。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Young‘s River">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          一步一步之ddia
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-25 23:06:03" itemprop="dateCreated datePublished" datetime="2023-11-25T23:06:03+08:00">2023-11-25</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-12-28 22:24:14" itemprop="dateModified" datetime="2023-12-28T22:24:14+08:00">2023-12-28</time>
              </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.2k</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="Chapter-1-Reliable-Scalable-and"><a href="#Chapter-1-Reliable-Scalable-and" class="headerlink" title="Chapter 1 Reliable Scalable and"></a>Chapter 1 Reliable Scalable and</h2><h3 id="常见的数据系统"><a href="#常见的数据系统" class="headerlink" title="常见的数据系统"></a>常见的数据系统</h3><ul>
<li>存储数据，以便之后再次使用 - 数据库</li>
<li>记住一些非常 <strong>重</strong>的操作结构，方便之后加速读取速度 - 缓存</li>
<li>允许用户以各种关键字搜索，以各种条件过滤数据 - 搜索引擎</li>
<li>源源不断的产生数据，并发发给其他进程进行处理 - 流式处理</li>
<li>定期处理累积的大量数据 - 批处理</li>
<li>进行消息的转发和分发 - 消息队列</li>
</ul>
<p>ddia 提供了一种典型的数据系统架构 1-1</p>
<p>实际使用系统设计中，存在很多取舍</p>
<ol>
<li>使用何种缓存策略？是旁路还是写穿透？</li>
<li>部分组件机器出现问题时，是保证可用性还是一致性</li>
<li>当机器一时难以恢复，如何保证数据的正确性和完整性</li>
<li>当负载增加时，是增加机器还是提升单机性能</li>
<li>设计对外的api时，是力求简单还是追求强大</li>
</ol>
<p>书中概括三个词 Reliablity （可靠性）、Scalability（可伸缩性）、Maintainablity（可维护性）。</p>
<h3 id="可靠性"><a href="#可靠性" class="headerlink" title="可靠性"></a>可靠性</h3><p>如何衡量</p>
<ul>
<li><p>功能性</p>
<ul>
<li>正常情况下，满足api给出的行为</li>
<li>用户输入/误入操作，能够正常处理</li>
</ul>
</li>
<li><p>性能性</p>
<ul>
<li>给定硬件和数据量下，能够满足承若的性能指标</li>
</ul>
</li>
<li><p>安全上</p>
<p>能够阻止未授权，恶意破坏</p>
</li>
</ul>
<h4 id="故障类型"><a href="#故障类型" class="headerlink" title="故障类型"></a>故障类型</h4><ul>
<li><p>硬件故障</p>
</li>
<li><p>软件错误</p>
</li>
<li><p>人为问题</p>
<ul>
<li><p>设计编码</p>
<ul>
<li>尽可能消除不必要的假说</li>
<li>进程间隔离</li>
<li>服务间熔断设计</li>
</ul>
</li>
<li><p>测试阶段</p>
<ul>
<li>尽可能引入第三方测试，尽量将测试平台自动化</li>
<li>单元测试、集成测试、e2e测试、混沌测试</li>
</ul>
</li>
<li><p>运行阶段</p>
<ul>
<li>详细的仪表盘</li>
<li>持续自检</li>
<li>报警机制</li>
<li>问题预案</li>
</ul>
</li>
<li><p>针对组织</p>
<p>科学的培训和管理</p>
</li>
</ul>
</li>
</ul>
<h3 id="可伸缩性"><a href="#可伸缩性" class="headerlink" title="可伸缩性"></a>可伸缩性</h3><p><strong>只有存活下来的产品才有资格谈伸缩，而过早的伸缩设计往往活不下去</strong></p>
<h4 id="衡量负载"><a href="#衡量负载" class="headerlink" title="衡量负载"></a>衡量负载</h4><p>load parameters(负载参数)</p>
<ul>
<li>应用日活月活</li>
<li>每秒web服务器发出的请求</li>
</ul>
<p>一般来说读多于写，twiiter 中大v发布用户的情况下，常见的处理有推和拉</p>
<ol>
<li>拉，每个人查看首页feed，从数据库拉取所有关注用户推文，合并后展现</li>
<li>推，为每个用户保存一个feed流视图，当用户发推文时，将其插入所有关注者的feed流视图</li>
</ol>
<h4 id="描述性能"><a href="#描述性能" class="headerlink" title="描述性能"></a>描述性能</h4><ol>
<li>吞吐量 throughput</li>
<li>响应时间 response time</li>
<li>延迟 latency</li>
</ol>
<h4 id="应对负载"><a href="#应对负载" class="headerlink" title="应对负载"></a>应对负载</h4><ol>
<li>纵向伸缩或者垂直伸缩：换具有更强大的性能机器。e.g. 大型机器学习训练</li>
<li>横向伸缩或者水平伸缩：并联很多廉价机，分摊负债，e.g. 马斯克造火箭</li>
</ol>
<p>针对不同应用场景：</p>
<p>首先。规模小，尽可能使用性能好一点的机器，省去麻烦</p>
<p>其次，可以上云，利用云的可伸缩性。</p>
<p>最后，实在不行再考虑自行设计可伸缩的分布式架构。</p>
<h3 id="可维护性"><a href="#可维护性" class="headerlink" title="可维护性"></a>可维护性</h3><p>软件整个生命周期来看，维护阶段绝对占大头。大部分人喜欢挖坑，不喜欢填坑。</p>
<ul>
<li>可运维性，运维团队无痛接手</li>
<li>简洁性，便于新手开发平滑上手，<strong>需要一个合理的抽象，并尽量消除各种复杂度，如，层次化抽象</strong></li>
<li>可演化性，便于后面需求快速适配，避免代码绑定在某种实现上，也可称为，可扩展性</li>
</ul>
<h4 id="可运维性"><a href="#可运维性" class="headerlink" title="可运维性"></a>可运维性</h4><p>人生苦短，关爱运维</p>
<ol>
<li>紧盯系统状态，出问题时快速恢复</li>
<li>恢复后，复盘问题，定位原因</li>
<li>定期对平台、库、组件进行更新升级</li>
<li>了解组件相互关系，避免级联故障</li>
<li>建立自动化配置管理、服务管理、更新升级机制</li>
<li>执行复杂维护任务，如将存储系统从一个数据中心搬到另一个数据中心</li>
<li>配置变更时，保证系统安全</li>
</ol>
<p>规范</p>
<ol>
<li>友好的文档和一致的运维规范</li>
<li>细致的监控仪表盘、自检、报警</li>
<li>通用的缺省配置</li>
<li>出问题时的自愈机制、无法自愈时允许管理员手动介入</li>
<li>将维护过程尽可能自动化</li>
<li>避免单点依赖，<strong>无论是机器还是人</strong></li>
</ol>
<h4 id="简洁性"><a href="#简洁性" class="headerlink" title="简洁性"></a>简洁性</h4><p>推荐一本书，A Philosophy of Software Design，讲如何在软件设计中定义、识别和降低复杂度。</p>
<p>复杂度的表现</p>
<ol>
<li>状态空间的膨胀</li>
<li>组件间的强耦合</li>
<li>不一致的术语和命名</li>
<li>为了提升性能的hack</li>
<li><strong>随处可见的补丁 workaround</strong></li>
</ol>
<p>需求很简单，但是不妨碍实现复杂：过多引入 <strong>额外复杂度</strong> ,通常是问题理解的不够本质，写出 <strong>流水账</strong>（没有任何抽象，abstraction）的代码。</p>
<p>如果你为一个问题找到合适的抽象，那么问题就解决了一半，拆分子问题，交互、边界：</p>
<ol>
<li>高级语言隐藏机器码、cpu和系统调用细节</li>
<li>sql隐藏了存储体系、索引结构、查询优化实现细节</li>
</ol>
<p>如何找到合适的抽象</p>
<ol>
<li>从计算机领域常见的抽象中找，比如缓存</li>
<li>从日常生活中常接触的概念找</li>
</ol>
<h4 id="可演化性"><a href="#可演化性" class="headerlink" title="可演化性"></a>可演化性</h4><p>系统需求没有变化，说明行业死了。否则需求一定是不断变。</p>
<p>应对之道：</p>
<ul>
<li>项目管理上，敏捷开发（应用层应对快速迭代）</li>
<li>系统设计上，合理抽象、合理封装、对修改关闭、对扩展开放</li>
</ul>
<h2 id="Chapter2-Data-Models-and-Query-Languages"><a href="#Chapter2-Data-Models-and-Query-Languages" class="headerlink" title="Chapter2 Data Models and Query Languages"></a>Chapter2 Data Models and Query Languages</h2><p>如何分析一个 *<em>数据模型 *</em>:</p>
<ol>
<li>基本考察点：数据基本元素，和元素之间的对应关系（一对多，多对多）</li>
<li>利用几种常用模型比较：关系模型（最流行）、文档模型（树状的），图模型（极大自由）</li>
<li>schema 模式：强Schema（写时约束）；弱Schema（读时解析）</li>
</ol>
<h3 id="关系模型vs文档模型"><a href="#关系模型vs文档模型" class="headerlink" title="关系模型vs文档模型"></a>关系模型vs文档模型</h3><h4 id="关系模型"><a href="#关系模型" class="headerlink" title="关系模型"></a>关系模型</h4><p>常见分类</p>
<ol>
<li>事务型（tp）：银行交易、火车票</li>
<li>分析型（ap）：数据报表、监控表盘</li>
<li>混合型（hap）</li>
</ol>
<blockquote>
<p>明明看起来更像表模型，为什么叫关系模型？</p>
<p>关系 relation说法来自集合论，指的是几个集合的笛卡尔的子集，R (D1*D2*D3)</p>
</blockquote>
<h4 id="NoSQL"><a href="#NoSQL" class="headerlink" title="NoSQL"></a>NoSQL</h4><p>Non-SQL-》Not only SQL，MongoDB、ElasticSearch，诞生的元素</p>
<ol>
<li>处于更大的数据集：更强的伸缩性、更高吞吐量</li>
<li>开源免费的兴起</li>
<li>特化的查询操作：关系数据库难以支持，比如图的多跳分析</li>
<li>表达能力更强：关系模型约束太严</li>
</ol>
<p>面向对象的嵌套性和关系数据库的平铺性</p>
<h4 id="文档模型"><a href="#文档模型" class="headerlink" title="文档模型"></a>文档模型</h4><p>天然的一对多、树形嵌套关系，如简历。</p>
<h4 id="网状模型"><a href="#网状模型" class="headerlink" title="网状模型"></a>网状模型</h4><h4 id="关系模型-1"><a href="#关系模型-1" class="headerlink" title="关系模型"></a>关系模型</h4><h3 id="数据查询语言"><a href="#数据查询语言" class="headerlink" title="数据查询语言"></a>数据查询语言</h3><ul>
<li>声明式语言<ul>
<li>描述控制逻辑而非执行流程</li>
<li>SQL、CSS、XSL</li>
<li>抽象程度高</li>
<li>与实现接耦，可以持续优化查询引擎性能</li>
<li>词法分析-》语法分析-〉语义分析-》生成执行计划-〉执行计划优化</li>
<li>声明式更具有多核潜力，给了更多运行优化空间</li>
</ul>
</li>
<li>命令式语言<ul>
<li>描述命令的执行流程，用一系列语言来不断改变状态</li>
<li>IMS，CODASYL，通用语言如C，C++，JS</li>
<li>与实现耦合较深</li>
<li>词法分析-》语法分析-〉语义分析-》中间代码生成-〉代码优化-》目标代码生成</li>
<li>命令式由于指定了代码执行顺序，编译时优化空间较小</li>
</ul>
</li>
</ul>
<h4 id="MapReduce"><a href="#MapReduce" class="headerlink" title="MapReduce"></a>MapReduce</h4><p>Google 的 Map Reduce 模型</p>
<ol>
<li>借鉴函数式编程</li>
<li>一种相当简单的编程模型，或者说原子的抽象，现在不太够用</li>
<li>但是在大数据处理工具匮乏的蛮荒时代（03以前），谷歌提出这套框架相当有开创性</li>
<li>Mapper Combiner Shuffle and Sort Reducer</li>
</ol>
<h4 id="MongoDb-的-MapReduce模型"><a href="#MongoDb-的-MapReduce模型" class="headerlink" title="MongoDb 的 MapReduce模型"></a>MongoDb 的 MapReduce模型</h4><p>MapReduce 特点</p>
<ol>
<li>要求Map和Reduce 是纯函数，无任何副作用，在任意地点，以任意次序执行多次，对相同的输入都能得到相同的输出，因此容易并发调度</li>
<li>非常底层、但表达能力强大的编程模型。可以基于其实现的sql等高级查询语言，如hive</li>
</ol>
<h2 id="Chapter-3-Storage-and-Retrieval"><a href="#Chapter-3-Storage-and-Retrieval" class="headerlink" title="Chapter 3: Storage and Retrieval"></a>Chapter 3: Storage and Retrieval</h2><p>本章主要聚焦在底层如何查询和存储，这其中，有个逻辑链条：使用场景 -》查询类型-〉存储格式</p>
<p>查询类型主要分为两类</p>
<table>
<thead>
<tr>
<th>引擎类型</th>
<th>请求数量</th>
<th>数据量</th>
<th>存储格式</th>
<th>用户</th>
<th>场景举例</th>
<th>产品举例</th>
</tr>
</thead>
<tbody><tr>
<td>OLTP</td>
<td>相对繁琐，侧重在线交易</td>
<td>总体和单次查询都相对小</td>
<td>多用行存</td>
<td>一般用户</td>
<td>银行交易</td>
<td>mysql</td>
</tr>
<tr>
<td>OLAP</td>
<td>相对较少</td>
<td>总体和单次查询都相对巨大</td>
<td>列存储</td>
<td>商业用户</td>
<td>商业分析</td>
<td>ClickHouse</td>
</tr>
</tbody></table>
<p>写文章的逻辑组织和架构很具有参考意义。</p>
<h3 id="驱动数据库的底层数据结构"><a href="#驱动数据库的底层数据结构" class="headerlink" title="驱动数据库的底层数据结构"></a>驱动数据库的底层数据结构</h3><p>本节由一个shell脚本出发，到一个相当简单但是可用的bitcask，然后引出LSM-Tree，他们都属于日志流范畴，之后转向存储引擎另一个流派-b树，最后探讨了-索引。</p>
<p>分析一下为什么work，也反映了日志结构存储最基本原理：</p>
<ol>
<li>set 在文件末尾追加了一个kv对</li>
<li>get 匹配所有的key，返回最后（也即最新）一条kv对中的value</li>
</ol>
<p>可以看出：写很快，但是读需要全文逐行扫描，会慢很多。典型的以读换写。为了加快读，我们需要构建 <strong>索引</strong> ：一种允许基于某个字段查找的额外数据结构。</p>
<p>索引从原数据中构建，只为加快查找。因此索引会耗费一定额外空间和插入时间（每次插入需要更新索引），即，重新以空间和写换取读。</p>
<h3 id="哈希索引"><a href="#哈希索引" class="headerlink" title="哈希索引"></a>哈希索引</h3><p>内存维护hashMap，key是查询key，value是kv条目的起始位置和长度</p>

    </div>

    
    
    
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

  
</div>
        <div class="reward-container">
  <div>辛苦码字分享，您的支持将鼓励我继续创作！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.jpg" alt="Issac Young 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.jpg" alt="Issac Young 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Issac Young
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://issacyoung.cn/2023/11/25/%E4%B8%80%E6%AD%A5%E4%B8%80%E6%AD%A5%E4%B9%8Bddia/" title="一步一步之ddia">http://issacyoung.cn/2023/11/25/一步一步之ddia/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

            <div class="social-item">
              <a target="_blank" class="social-link" href="/atom.xml">
                <span class="icon">
                  <i class="fa fa-rss"></i>
                </span>

                <span class="label">RSS</span>
              </a>
            </div>
    </div>
  </div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2023/11/19/%E4%B8%80%E6%AD%A5%E4%B8%80%E6%AD%A5%E4%B9%8Bwebflux/" rel="prev" title="一步一步之webflux">
      <i class="fa fa-chevron-left"></i> 一步一步之webflux
    </a></div>
      <div class="post-nav-item">
    <a href="/2024/02/04/%E9%9D%A2%E5%90%91%E7%BB%A9%E6%95%88%E7%BC%96%E7%A8%8B/" rel="next" title="面向绩效编程">
      面向绩效编程 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-1-Reliable-Scalable-and"><span class="nav-number">1.</span> <span class="nav-text">Chapter 1 Reliable Scalable and</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#常见的数据系统"><span class="nav-number">1.1.</span> <span class="nav-text">常见的数据系统</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#可靠性"><span class="nav-number">1.2.</span> <span class="nav-text">可靠性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#故障类型"><span class="nav-number">1.2.1.</span> <span class="nav-text">故障类型</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#可伸缩性"><span class="nav-number">1.3.</span> <span class="nav-text">可伸缩性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#衡量负载"><span class="nav-number">1.3.1.</span> <span class="nav-text">衡量负载</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#描述性能"><span class="nav-number">1.3.2.</span> <span class="nav-text">描述性能</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#应对负载"><span class="nav-number">1.3.3.</span> <span class="nav-text">应对负载</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#可维护性"><span class="nav-number">1.4.</span> <span class="nav-text">可维护性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#可运维性"><span class="nav-number">1.4.1.</span> <span class="nav-text">可运维性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#简洁性"><span class="nav-number">1.4.2.</span> <span class="nav-text">简洁性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#可演化性"><span class="nav-number">1.4.3.</span> <span class="nav-text">可演化性</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter2-Data-Models-and-Query-Languages"><span class="nav-number">2.</span> <span class="nav-text">Chapter2 Data Models and Query Languages</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#关系模型vs文档模型"><span class="nav-number">2.1.</span> <span class="nav-text">关系模型vs文档模型</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#关系模型"><span class="nav-number">2.1.1.</span> <span class="nav-text">关系模型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#NoSQL"><span class="nav-number">2.1.2.</span> <span class="nav-text">NoSQL</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#文档模型"><span class="nav-number">2.1.3.</span> <span class="nav-text">文档模型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#网状模型"><span class="nav-number">2.1.4.</span> <span class="nav-text">网状模型</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#关系模型-1"><span class="nav-number">2.1.5.</span> <span class="nav-text">关系模型</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数据查询语言"><span class="nav-number">2.2.</span> <span class="nav-text">数据查询语言</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#MapReduce"><span class="nav-number">2.2.1.</span> <span class="nav-text">MapReduce</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#MongoDb-的-MapReduce模型"><span class="nav-number">2.2.2.</span> <span class="nav-text">MongoDb 的 MapReduce模型</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Chapter-3-Storage-and-Retrieval"><span class="nav-number">3.</span> <span class="nav-text">Chapter 3: Storage and Retrieval</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#驱动数据库的底层数据结构"><span class="nav-number">3.1.</span> <span class="nav-text">驱动数据库的底层数据结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#哈希索引"><span class="nav-number">3.2.</span> <span class="nav-text">哈希索引</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Issac Young"
      src="/images/author.jpg">
  <p class="site-author-name" itemprop="name">Issac Young</p>
  <div class="site-description" itemprop="description">现代生活工作节奏越来越快，需要有时间和空间沉淀积累，将知识点规划成树，记录自己的感悟心得。</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">26</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/IssacYoung2013" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;IssacYoung2013" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:issacyoung@msn.cn" title="E-Mail → mailto:issacyoung@msn.cn" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2020 – 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Issac Young</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">64k</span>
</div>


        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/clicklove.js"></script>

